var mysql = require('mysql');
var pool = mysql.createPool({
    host: '123.56.165.191',
    user: 'lanny',
    password: 'BD78F921',
    database: 'ultrax', // 前面建的user表位于这个数据库中
    port: 3306
});
pool.getConnection(function (err, connection) {
    if (err) {
        console.log(err);
        return;
    }
    addBasic({
        symbol: 'symbol',
        name_cn: 'name_cn',
        name_en: 'name_en',
        introduction: 'introduction',
        country: 'country',
        issuer: 'issuer',
        issue_date: 'issue_date',
        index: 'index',
        etf_type: 'etf_type',
        go_long: 'go_long',
        is_lever: 'is_lever',
        is_hedging: 'is_hedging'
    }, connection, function (data) {
        console.log(data);
    });
});
var sqlBasic = 'INSERT INTO etf_basic_info(etf_id, etf_symbol,' +
    ' name_cn,name_en ,introduction,cur_type,stock_site,' +
    'country,issuer,issue_date,index,etf_type,go_long,' +
    'is_lever,is_hedging) VALUES(0,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
function addBasic(obj, conn, cb) {
    var arr = [];
    arr.push(obj.symbol);
    arr.push(obj.name_cn);
    arr.push(obj.name_en);
    arr.push(obj.introduction || '');
    arr.push(obj.cur_type || '');
    arr.push(obj.stock_site || '');
    arr.push(obj.country);
    arr.push(obj.issuer);
    arr.push(obj.issue_date);
    arr.push(obj.index);
    arr.push(obj.etf_type);
    arr.push(obj.go_long);
    arr.push(obj.is_lever);
    arr.push(obj.is_hedging);
    conn.query(sqlBasic, arr, function (err, result) {
        if (err) {
            cb(err);
            return;
        }
        cb(result);
    });
}